/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kedacom.demo.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class MySQLUtil {
    private static final Logger logger = Logger.getLogger(MySQLUtil.class.getName());
    private static final String connectionStr = "jdbc:mysql://127.0.0.1:3306/test?user=root&password=itserver&useUnicode=true&characterEncoding=UTF8";
    private static final String driverClassName = "com.mysql.jdbc.Driver";
    private static  Connection connection;
    private static  Statement statement;
    
    static {
        try {
            // load the sqlite-JDBC driver using the current class loader
            Class.forName(driverClassName);
        } catch (ClassNotFoundException ex) {
            logger.log(Level.SEVERE, "无法找到MySQL-JDBC驱动", ex);
        }

        try {
            connection = DriverManager.getConnection(connectionStr);

        }
        catch (SQLException ex) {
            logger.log(Level.SEVERE, "无法创建数据库连接对象", ex);
        }
        try {
            statement = connection.createStatement();
            statement.setQueryTimeout(30);  // set timeout to 30 sec.
        }
        catch (SQLException ex) {
            logger.log(Level.SEVERE, "无法创建数据库连接对象", ex);
        }
       
    }    

}
